package com.yycx.module.bus.provider.service;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.base.service.IBaseService;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.module.bus.client.entity.*;
import com.yycx.module.bus.client.entity.hy.HyOrder;
import com.yycx.module.bus.client.enums.AmountTypeEnum;
import com.yycx.module.bus.client.vo.HyBankItem;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 付款单 接口
 *
 * @author flyme
 * @date 2020-09-07
 */
public interface BusPaymentService extends IBaseService<BusPayment> {

    /**
     * 根据订单ID查询付款单
     *
     * @param orderId
     * @return
     */
    BusPayment getByOrderIdAndAmountType(Serializable orderId, AmountTypeEnum amountType);

    /**
     * 根据父ID和单据类型查询
     *
     * @param parentId
     * @param amountType
     * @return
     */
    BusPayment getByParentIdAndAmountType(Serializable parentId, AmountTypeEnum amountType);

    /**
     * 按类型查询订单款项单据
     *
     * @param orderId
     * @param amountType
     * @param paymentState
     * @return
     */
    List<BusPayment> selectByOrderIdAndAmountType(Serializable orderId, AmountTypeEnum amountType, Integer paymentState);


    /**
     * 查询认款单
     *
     * @param orderId
     * @param amountType
     * @return
     */
    List<BusPayment> selectByOrderIdAndAmountType(Serializable orderId, AmountTypeEnum amountType);

    /**
     * 查询收款单
     *
     * @param orderId
     * @param bankId
     * @param amountType
     * @return
     */
    BusPayment getByOrderIdAndAmountType(Serializable orderId, Long bankId, AmountTypeEnum amountType);


    /**
     * 根据订单明细ID查询付款单
     *
     * @param orderDetailsId
     * @return
     */
    BusPayment getByOrderDetailsIdAndAmountType(String orderDetailsId, AmountTypeEnum amountType);

    /**
     * 查询回款信息
     *
     * @param orderId
     * @return
     */
    List<EntityMap> getOrderReturnDetails(Long orderId);

    /**
     * 查询非两票回款信息
     *
     * @param orderId
     * @return
     */
    List<EntityMap> getHyOrderReturnDetails(Long orderId);

    /**
     * 根据paymentId查询
     *
     * @param paymentId
     * @param amountType
     * @return
     */
    BusPayment getByPaymentIdAndAmountType(Long paymentId, AmountTypeEnum amountType);


    List<EntityMap> getByOrderId(Serializable orderId);


    /**
     * 查询订单明细已经结算金额
     *
     * @param orderDetailsId
     * @param paymentState
     * @return
     */
    BigDecimal totalSettleAmount(Long orderDetailsId, Integer paymentState);


    /**
     * 统计已开票金额
     *
     * @param settleApplyId
     * @return
     */
    BigDecimal totalSettleAmount(String settleApplyId);


    /**
     * 计算所选数据开票金额
     *
     * @param selectIds
     * @return
     */
    BigDecimal totalAmount(String selectIds);


    /**
     * 统计未开票数量
     *
     * @param settleApplyId
     * @return
     */
    Integer countInvoiceNum(String settleApplyId);


    /**
     * 统计开票支付数量
     *
     * @param settleApplyId
     * @return
     */
    Integer countInvoicePayNum(String settleApplyId);


    /**
     * 添加保证金收款认款单
     *
     * @param busOrder
     * @return
     */
    ResultBody addCustomBondPayment(BusOrder busOrder);


    /**
     * 添加保证金收款单
     *
     * @param busOrder
     * @param paymentState
     * @return
     */
    BusPayment addCustomBondPayment(BusOrder busOrder, Integer paymentState);


    /**
     * 添加资保金认款单
     *
     * @param hyOrder
     * @param bankItem
     * @return
     */
    BusPayment addCustomBondPayment(HyOrder hyOrder, HyBankItem bankItem);


    /**
     * 添加预付款收款单
     *
     * @param customBalance
     * @return
     */
    BusPayment addCustomBalancePayment(BusCustomBalance customBalance);


    /**
     * 添加全款认款单
     *
     * @param order
     * @param bankItem
     * @return
     */
    BusPayment addOrderPayment(HyOrder order, HyBankItem bankItem);

    /**
     * 添加资保金收款单
     *
     * @param salemanBalance
     * @return
     */
    BusPayment addSaleManBalancePayment(BusSalemanBalance salemanBalance);


    /**
     * 添加质押金收款单
     *
     * @param deposit
     * @return
     */
    BusPayment addBusDepositPayment(BusDeposit deposit);

    BusPayment addConsumPayment(BusConsumption consumption);


    /**
     * 删除现款资保金认款单
     *
     * @param orderId
     * @return
     */
    ResultBody deleteOrderPayment(Serializable orderId);


    /**
     * 删除审批单
     *
     * @param amountType
     * @param orderDetailsId
     * @return
     */
    ResultBody deleteByAmountType(AmountTypeEnum amountType, Long orderDetailsId);


    /**
     * 删除审批单
     *
     * @param parentId
     * @return
     */
    ResultBody deleteByParentId(Serializable parentId);


    /**
     * 更新状态
     *
     * @param paymentId
     * @param processInstanceId
     * @param paymentState
     * @return
     */
    Boolean updatePaymentState(Serializable paymentId, String processInstanceId, Integer paymentState);


    /**
     * 更新状态
     *
     * @param paymentId
     * @param paymentState
     * @return
     */
    Boolean updatePaymentState(Long paymentId, Integer paymentState);


    /**
     * 关联订单
     *
     * @param paymentId
     * @param orderId
     * @return
     */
    Boolean bindOrder(Long paymentId, String orderId);

    /**
     * 解除订单关联
     *
     * @param paymentId
     * @return
     */
    Boolean unBindOrder(Long paymentId);

    /**
     * 更新状态
     *
     * @param orderId
     * @param paymentState
     * @return
     */
    Boolean updatePaymentState(String orderId, Integer paymentState);


    /**
     * 更新状态
     *
     * @param paymentId
     * @param paymentState
     * @param payUserId
     * @param payDate
     * @return
     */
    Boolean updatePaymentState(Long paymentId, Integer paymentState, Long payUserId, String payDate);


    /**
     * 更新打印状态图
     *
     * @param paymentId
     * @return
     */
    Boolean updatePrintTag(Long paymentId);

    /**
     * 清空流程实例ID
     *
     * @param processInstanceId
     * @return
     */
    Boolean clearProcessInstanceId(String processInstanceId);

    /**
     * 获取单据打印信息
     *
     * @param paymentId
     * @param amountType
     * @return
     */
    ResultBody getPrintInfo(Long paymentId, AmountTypeEnum amountType);


    /**
     * 获取单据打印信息
     *
     * @param paymentId
     * @return
     */
    ResultBody getHyPrintInfo(Long paymentId);

    /**
     * 获取认款打印信息
     *
     * @param paymentId
     * @return
     */
    ResultBody getRenkuanInfo(String paymentId);

    /**
     * 获取回款单打印信息
     *
     * @param paymentId
     * @return
     */
    ResultBody getHuikuanInfo(Long paymentId);


    /**
     * 补录结算数据
     *
     * @param orderDetailsId
     * @return
     */
    ResultBody initSettlePayment(Long orderDetailsId);


    /**
     * 获取开票结算信息
     *
     * @param selectIds
     * @return
     */
    EntityMap getInvoiceInfo(String selectIds);

    /**
     * 获取结算申请信息
     *
     * @param settleType 结算范围
     * @param selectIds
     * @return
     */
    ResultBody getSettleApplyInfo(Integer settleType, String selectIds);

    /**
     * 获取部门结算申请信息
     *
     * @param selectIds
     * @return
     */
    ResultBody getDeptSettleApplyInfo(String selectIds);

    /**
     * 获取结算支付信息
     *
     * @param selectIds
     * @return
     */
    ResultBody getSettlePayInfo(String selectIds);

    /**
     * 获取退保证金信息
     *
     * @param selectIds
     * @return
     */
    ResultBody getRefundBondInfo(String selectIds);

    /**
     * 获取退保证金信息
     *
     * @param selectIds
     * @return
     */
    ResultBody getReturnInfo(String selectIds);

    /**
     * 获取退货款申请信息
     *
     * @param selectIds
     * @return
     */
    ResultBody getRefundHkInfo(String selectIds);

    /**
     * 删除认款单
     *
     * @param amountType
     * @param orderId
     * @return
     */
    ResultBody removeByOrderId(AmountTypeEnum amountType, String orderId);

    /*************************非两票*****************************************/
    /**
     * 查询收款单
     *
     * @param invoiceId
     * @param saleManId
     * @return
     */
    BusPayment getSettlePayment(Long invoiceId, Long saleManId);

    /**
     * 清空开票ID
     *
     * @param invoiceId
     * @return
     */
    Boolean clearInvoiceId(Serializable invoiceId);

    /**
     * 打印开票申请单
     *
     * @param inoviceId
     * @return
     */
    ResultBody getInvoicePrintInfo(Long inoviceId);

    /**
     * 更新剩余金额
     *
     * @param paymentId
     * @param surplusAmount
     */
    Boolean updateSurplusAmount(Long paymentId, BigDecimal surplusAmount);


    /***
     * 更新余额
     * @param paymentId
     * @param useAmount
     * @return
     */
    Boolean addSurplusAmount(Long paymentId, BigDecimal useAmount);

    /**
     * 更新发货金额
     *
     * @param paymentId
     * @param saleAmount
     */
    Boolean updateSaleAmount(Long paymentId, BigDecimal saleAmount);

    /**
     * 根据父ID查询
     * @param paymentId
     * @return
     */
    List<Long> selectByParentId(Long paymentId);
}
